package com.xiaohei.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaohei.crm.common.result.Result;
import com.xiaohei.crm.dao.Customer;
import com.xiaohei.crm.service.CustomerService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: UserController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/6/19 15:06
 * Version 1.0
 */
@RestController
@RequiredArgsConstructor
@CrossOrigin
public class CustomerController {
    private final CustomerService customerService;

    /**
     * 分页查询用户信息
     * @return
     */
    @GetMapping("/customer/findByPage")
    public Result<IPage> findByPage(){
        return customerService.findByPage();
    }

    /**
     * 添加用户
     * @param
     * @return
     */
    @PostMapping("/customer")
    public Result save(@RequestBody Customer customer){
        customerService.saveCustomer(customer);
        return Result.ok();
    }

    /**
     * 修改用户信息
     * @param customer
     * @return
     */
    @PutMapping("/customer")
    public Result update(@RequestBody Customer customer){
        customerService.updateByCustomerId(customer);
        return Result.ok();
    }

    /**
     * 逻辑删除用户
     * @param id
     * @return
     */
    @DeleteMapping("customer/{id}")
    public Result<String> deleteByUsername(@PathVariable("id") String id){
        customerService.removeByCustomerName(id);
        return Result.ok();
    }
}
